#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 500005;
int n, m;
int q[N], a[N];
long long f[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("蓝蓝的棋盘.in", "r", stdin);
  freopen("蓝蓝的棋盘.out", "w", stdout);
#endif
#endif
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  f[n] = 0;
  int l = 1, r = 0;
  q[++r] = n;
  for (int i = n; ~i; --i) {
    while (l <= r && q[l] > i + m) ++l;
    f[i] = -a[i] - f[q[l]];
    while (l <= r && f[q[r]] >= f[i]) --r;
    q[++r] = i;
  }
  printf("%lld", f[0]);
  return 0;
}